package basic_1022;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner=new Scanner(System.in);
		
		int N=scanner.nextInt();
		
		Map<String, Integer>map=new HashMap<String, Integer>();
		String bestSchool = "";
		int maxScore=0;
		
		for(int i=0;i<N;i++) {
			String id=scanner.next();
			int score=scanner.nextInt();
			int sumScore=score;
			if(map.containsKey(id)) {
				sumScore+=map.get(id);
			}
			map.put(id, sumScore);
			if(sumScore>maxScore) {
				bestSchool=id;
				maxScore=sumScore;
			}
		}
		scanner.close();
		System.out.println(bestSchool+" "+maxScore);
	}
}
